package com.jinhu.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.jinhu.Entity.wxuserinfo;
import com.jinhu.ResultEntity;
import com.jinhu.Service.IAccountService;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;

@Controller
public class AccountController {
    @Inject
    IAccountService accountService;
    @Mapping("/getWxId")
    public ResultEntity getWxId(@Body JSONObject json){
        if(JSONUtil.isNull(json)) return ResultEntity.no("参数为空");
        wxuserinfo openid = accountService.login(json.getStr("openid"));
        return ResultEntity.ok("登录成功",openid);
    }

    @Mapping("/getUserInfo")
    public ResultEntity getUserInfo(){
        return null;
    }

    @Mapping("/register")
    public ResultEntity register(@Body JSONObject json){
        if(JSONUtil.isNull(json)) return ResultEntity.no("参数为空");
        wxuserinfo openid = accountService.register(json.getStr("openid"));
        return ResultEntity.ok("注册成功",openid);
    }


}
